package org.iabako.client.ui.form.business.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
import org.iabako.client.config.page.PageEnum;
import org.iabako.client.navigation.NavigationController;
import org.iabako.client.ui.form.AbstractForm;
import org.iabako.client.ui.layout.field.IField;
import org.iabako.client.ui.layout.field.LabelText;
import org.iabako.client.ui.layout.widget.conversation.ConversationTable;
import org.iabako.shared.entity.business.AbstractEntity;
import org.iabako.shared.entity.business.Client;

import java.util.List;

/**
 * Created by jose on 12/02/15.
 */
public class ClientConversationsForm extends AbstractForm {

    interface MyUiBinder extends UiBinder<HTMLPanel, ClientConversationsForm> {
    }

    protected MyUiBinder binderForm = GWT.create(MyUiBinder.class);

    @UiField
    HTMLPanel conversationsPanel;
    @UiField
    LabelText addConversationAction;

    private Client client;
    public ConversationTable conversationTable;


    public ClientConversationsForm() {
        initWidget(binderForm.createAndBindUi(this));

        addConversationAction.getLabel().addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                NavigationController.getInstance().goTo(PageEnum.ConversationCreate, parentForm);
            }
        });
    }

    public void setClient(Client client) {
        this.client = client;
    }

    @Override
    public void initialize() {
        if (client != null && conversationTable == null) {
            conversationTable = new ConversationTable(parentForm, client);
            conversationTable.show(conversationsPanel);
        }
    }

    @Override
    protected List<IField> getMandatoryFields() {
        return null;
    }

    @Override
    protected AbstractEntity getEntity() {
        return null;
    }

    @Override
    public boolean validate() {
        return false;
    }
}